/**
 * 定义视频模块
 */
(function(window, angular, undefined){

	var component = angular.module('water.common.video',[]);
	
	/**
	 * 视频播放组件
	 */
	component.directive("comVideo", function() {
		return {
		    restrict: "A",     
		    require : "ngModel",
		    scope: {              // 设置指令对于的scope 
		      height:"@",//视频组件高度
		      width:"@",//视频组件宽度
		      model:'=ngModel',//视频播放地址
		      componentObject:"=componentObject"
		    },
		    template: function( element, attrs){
		    	var html = '<video id="my-video" class="video-js" controls preload="auto" '+
		 		    'data-setup="{}">'+
		 		   	'<source id="videosrc" src="" type="video/mp4">'+
		 		   	'<p class="vjs-no-js">'+
		 		   	'To view this video please enable JavaScript, and consider upgrading to a web browser that'+
		 		   	'<a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>'+
		 		   	'</p>'+
			    '</video>';
		    	return html;
		    },
		    controller: [ "$scope", function ($scope) {
		    	
		    }], 
		    link:function($scope, elm, attrs, controller){
		    	$("video",elm).attr("width",$scope.width);
		    	$("video",elm).attr("height",$scope.height);
		    	var myPlayer = videojs($("video",elm)[0]);
		    	
		    	/**
		    	 * 暴露接口
		    	 */
		    	$scope.componentObject = myPlayer;
				
		    	controller.$render = function(){
		    		console.log(controller.$viewValue);
		    		myPlayer.src(controller.$viewValue);
					myPlayer.play();
		    	}
	        }
		 } 
	});
}(window, angular));